package com.css.Thread;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class ThreadDownload {
    public static void main(String[] args) {
        TestDownImgs testDownImgs=new TestDownImgs("https://www.baidu.com/img/baidu_jgylogo3.gif", "D:\\testImage\\copy1.png");
        TestDownImgs testDownImgs2=new TestDownImgs("https://www.baidu.com/img/baidu_resultlogo@2.png", "D:\\testImage\\copy2.png");
        testDownImgs.start();
        testDownImgs2.start();
    }

}
class TestDownImgs extends Thread{
    private String url;
    private String FileName;
    public TestDownImgs(String url,String FileName){
        this.url=url;
        this.FileName=FileName;
    }

    @Override
    public void run() {
//        super.run();
        WebDownLoader webDownLoader=new WebDownLoader();
        webDownLoader.downloader(url,FileName);
        System.out.println("下载文件"+FileName);
    }
}
//下载图片类
class WebDownLoader{
    public void downloader(String url,String fliename){
        try {
            FileUtils.copyURLToFile(new URL(url),new File(fliename));
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("io异常");
        }

    }
}
